package com.springboot.mybatis.service.collectiondemo;

import com.springboot.mybatis.entity.User;
import com.springboot.mybatis.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author sunyt
 * @date 2020/7/14 14:15
 */
@Service
public class UserService {

    @Autowired(required=false)
    private UserMapper userMapper;

    public String show() {
        return "Hello World!";
    }


/*    public String insert(String name, int age) { // 插入一条记录
        User user = new User();
        user.setName(name);
        user.setAge(age);
        userMapper.insert(user);
        return "Insert ( \""+name+"\", age"+age+") OK!";
    }*/

    public String insert(User user) { // 插入一条记录
        user.setName(user.getName());
        user.setAge(user.getAge());
        userMapper.insert(user);
        return "Insert ( \"" + user.getName() + "\", age" + user.getAge() + ") OK!";
    }

    public List<User> select(int age) {
        return userMapper.select(age);
    }
}
